﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.GualityGroup;
using MVC_System.DTO.GualityProject;
using Newtonsoft.Json;
using WMS_MAV;

namespace MVC_System.Controllers
{
    public class GualityProjectController : Controller
    {
        private readonly IConfiguration _configuration;
        public GualityProjectController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult GualityProjectShowView()
        {
            return View();
        }
        public async Task<ActionResult> GualityProjectShow(GualityProjectShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/GualityProject/GetGualityProject?pageindex=" + dto.pageindex + "&pagesize=" + dto.pagesize + "&gualityProjectNumbering=" + dto.gualityProjectNumbering + "&AddTime=" + dto.AddTime;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> GualityProjectAdd(GualityProjectAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/GualityProject/AddGualityProject";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        public async Task<ActionResult> GualityProjectDelete(GualityProjectDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/GualityProject/DeleteGualityProject";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        public async Task<ActionResult> GualityProjectModel(GualityProjectModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/GualityProject/ModelGualityProject?gualityProjectId=" + dto.gualityProjectId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> GualityProjectUpdate(GualityProjectUpdateDTO obj1, string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "HysSwagger/api/GualityProject/UpdateGualityProject";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
    }
}
